package com.yuwenxin.dao.impl;

import com.yuwenxin.bean.FriendList;
import com.yuwenxin.bean.User;
import com.yuwenxin.core.BaseDaoImpl;
import com.yuwenxin.core.BaseQueryModel;
import com.yuwenxin.dao.FriendListDao;

import java.sql.ResultSet;

public class FriendListDaoImpl extends BaseDaoImpl implements FriendListDao {

    @Override
    public String getSelectAllSql() {
        return "select * from friendlist";
    }

    @Override
    public String getSelectByNameSql() {
        return "select * from friendlist where friendlistName = ?";
    }

    @Override
    public String getFuzzyFindSql() {
        return "select * from friendlist where friendlistName like ?";
    }

    @Override
    public String getUpdateSql(Object object) {
        return null;
    }

    @Override
    public String getDeleteSql() {
        return "delete * from friendlist where idfriendlist = ?";
    }

    @Override
    public String getSelectByIdSql() {
        return "select * from friendlist where idfriendlist = ?";
    }

    @Override
    public String getInsertSql(Object object) {
        FriendList friendList = (FriendList) object;
        String friendlistName = friendList.getFriendListName();
        int belongedUserid = friendList.getBelongedUserid();
        return "insert into friendlist (friendlistName, belongedUserid) values ('"
                + friendlistName + "'," + belongedUserid + ")";
    }

    @Override
    public String getConditionSql(BaseQueryModel queryModel) {
        return null;
    }

    @Override
    public Object toEntity(ResultSet rs) throws Exception {
        FriendList friendList = new FriendList();
        friendList.setId(rs.getInt("idfriendlist"));
        friendList.setFriendListName(rs.getString("friendlistName"));
        friendList.setBelongedUserid(rs.getInt("belongedUserid"));
        return friendList;
    }
}
